<?php
	$page_name = $page['path'];
	
	if ( $page_name == 'home' )
	{
		echo '<div class="page_title"><h1>News and Events</h1></div><br />';
		$news_query = $this->MNews->getAllActiveNews();
		if ( count($news_query) > 0 )
		{
			echo '<div class="box-news">';
			echo '<div class="post_title">News</div>';
			foreach ( $news_query as $key => $news )
			{
				echo '<div class="post_description">';
				echo anchor("newsandevents/news/".$news['path'],$news['title']);
				echo '<p>'.$news['longdesc'].'</p>';
				echo '</div>';
			}
			echo '</div>';
		}
		
		// Get events
		$events_query = $this->MEvent->getAllActiveEvents();
		
		if ( count($events_query) > 0 )
		{
			echo '<div class="box-events">';
			echo '<div class="post_title">Events</div>';
			foreach ( $events_query as $key => $events )
			{
				echo '<div class="post_description">';
				echo anchor("newsandevents/news/".$events['path'],$events['title']);
				echo '<p>'.$events['longdesc'].'</p>';
				echo '</div>';
			}
			echo '</div>';
		}
		
		// Student Results
		$student_results = $this->MStudResult->getAllStudResults();
		if ( count($student_results) > 0 )
		{
			echo '<div class="post_title" style="margin-top:20px;"> Student Results </div>';
			
			$limit_student_result = 1;
			foreach ( $student_results as $key => $studresult )
			{
				if ( $limit_student_result <= 6 )
				{
					$year = $studresult['year'];
					$group = $studresult['group'];
					$semester = $studresult['semester'];
					
					echo '<div style="width:210px;float:left;margin-right:20px;margin-bottom:10px;">';
						$image_src = base_url().'images/studresult/'.$studresult['result_src'];
						echo '<img title="view image" class="img-popup" style="width:210px;cursor:pointer;max-width:210px;height:auto;border:2px solid #FFFFFF;box-shadow:0 0 3px rgba(0, 0, 0, 0.5);" src="'.$image_src.'" />';
						echo '<p style="text-align:center;margin-top:2px;">Year '.$year.' - Group '.$group.' - Semester '.$semester.'</p>';
					echo '</div>';
				}
				$limit_student_result += 1;
			}
			
			echo anchor("page/details/student-result/","<button class='btn' type='button' style='background:#291670;color:white;'>More Student Result here...</button>",array('onclick'=>'showurl('.base_url().')'));
		}
		
		// Student Schedules
		$student_schedules = $this->MStudentSchedule->getAllStudentSchedule();
		if ( count($student_schedules) > 0 )
		{
			echo '<div class="post_title" style="margin-top:20px;"> Student Schedules </div>';
			
			$limit_student_schedule = 1;
			foreach ( $student_schedules as $key => $student_schedule )
			{
				if ( $limit_student_schedule <= 6 )
				{
					$year = $student_schedule['year'];
					$group = $student_schedule['group'];
					$semester = $student_schedule['semester'];
					
					echo '<div style="width:210px;float:left;margin-right:20px;margin-bottom:10px;">';
						$image_src = base_url().'images/studentschedule/'.$student_schedule['schedule_src'];
						echo '<img title="view image" class="img-popup" style="width:210px;cursor:pointer;max-width:210px;height:auto;border:2px solid #FFFFFF;box-shadow:0 0 3px rgba(0, 0, 0, 0.5);" src="'.$image_src.'" />';
						echo '<p style="text-align:center;margin-top:2px;">Year '.$year.' - Group '.$group.' - Semester '.$semester.'</p>';
					echo '</div>';
				}
				$limit_student_schedule += 1;
			}
			
			echo anchor("page/details/student-schedule/","<button class='btn' type='button' style='background:#291670;color:white;'>More Student Schedule here...</button>",array('onclick'=>'showurl('.base_url().')'));
		}
	}
	
	else
	{
		$external_resources = $page['external_content'];
		
		if ( $external_resources == 'news' )
		{
			echo '<div class="page_title"><h1>News and Events</h1></div><br />';
			$news_query = $this->MNews->getAllActiveNews();
			if ( count($news_query) > 0 )
			{
				echo '<div class="box-news">';
				echo '<div class="post_title">News</div>';
				foreach ( $news_query as $key => $news )
				{
					echo '<div class="post_description">';
					echo anchor("newsandevents/news/".$news['path'],$news['title']);
					echo '<p>'.$news['longdesc'].'</p>';
					echo '</div>';
				}
				echo '</div>';
			}
			
			// Get events
			$events_query = $this->MEvent->getAllActiveEvents();
			
			if ( count($events_query) > 0 )
			{
				echo '<div class="box-events">';
				echo '<div class="post_title">Events</div>';
				foreach ( $events_query as $key => $events )
				{
					echo '<div class="post_description">';
					echo anchor("newsandevents/news/".$events['path'],$events['title']);
					echo '<p>'.$events['longdesc'].'</p>';
					echo '</div>';
				}
				echo '</div>';
			}
		}
		else if ( $external_resources == 'course' )
		{
			echo '<div class="page_title"><h1>Resources</h1></div><br />';
			
			$courses = $this->MLecturers->getAllCourses();
			if ( count($courses) )
			{
				foreach ( $courses as $key => $course )
				{
					$course_lower = strtolower($course['title']);
					$course_slug = str_replace(" ", "-", $course_lower);
					$course_title = '<h4 style="color:blue;margin-bottom:5px;">'.$course['title'].'</h4>';
					
					echo '<div style="margin-bottom:20px;">';
						echo anchor("courses/details/".$course_slug, $course_title,array('onclick'=>'showurl('.base_url().')'));
						echo '<p>'.$course['longdesc'].'</p>';
					echo '</div>';
				}
			}
		}
		
		// Lecturers
		else if ( $external_resources == 'lecturer' )
		{
			echo '<div class="page_title"><h1>Lecturers</h1></div><br />';
			
			$lecturers = $this->MLecturers->getAllLecturers();
			if ( count($lecturers) )
			{
				foreach ( $lecturers as $key => $lecturer )
				{
					$username = $lecturer['username'];
					$lecturer_name = 'Lec. <strong>'.$lecturer['lastname'].' '.$lecturer['firstname'].'</strong>';
					
					echo '<div style="width:150px;float:left;margin-right:20px;margin-bottom:10px;">';
						$image_src = base_url().'css/images/lecturer.png';
						$lecturer_img = '<img title="view image" style="width:1680px;cursor:pointer;max-width:150px;height:auto;border:2px solid #FFFFFF;box-shadow:0 0 3px rgba(0, 0, 0, 0.5);border-radius:11px;" src="'.$image_src.'" />';
						echo anchor("lecturers/profile/".$username, $lecturer_img, array('onclick'=>'showurl('.base_url().')'));
						echo '<p style="text-align:center;margin-top:2px;">';
							echo anchor("lecturers/profile/".$username, $lecturer_name,array('onclick'=>'showurl('.base_url().')'));
						echo '</p>';
					echo '</div>';
				}
			}
		}
		else if ( $external_resources == 'student_result' )
		{
			echo '<div class="page_title"><h1>Student Results</h1></div><br />';
			
			$studresults = $this->MStudResult->getAllStudResults();
			if ( count($studresults) )
			{
				foreach ( $studresults as $key => $studresult )
				{
					$year = $studresult['year'];
					$group = $studresult['group'];
					$semester = $studresult['semester'];
					
					echo '<div style="width:210px;float:left;margin-right:20px;margin-bottom:10px;">';
						$image_src = base_url().'images/studresult/'.$studresult['result_src'];
						echo '<img title="view image" class="img-popup" style="width:210px;cursor:pointer;max-width:210px;height:auto;border:2px solid #FFFFFF;box-shadow:0 0 3px rgba(0, 0, 0, 0.5);" src="'.$image_src.'" />';
						echo '<p style="text-align:center;margin-top:2px;">Year '.$year.' - Group '.$group.' - Semester '.$semester.'</p>';
					echo '</div>';
				}
			}
		}
		else if ( $external_resources == 'student_schedule' )
		{
			echo '<div class="page_title"><h1>Student Schedules</h1></div><br />';
			
			$student_schedules = $this->MStudentSchedule->getAllStudentSchedule();
			if ( count($student_schedules) )
			{
				foreach ( $student_schedules as $key => $student_schedule )
				{
					$year = $student_schedule['year'];
					$group = $student_schedule['group'];
					$semester = $student_schedule['semester'];
					
					echo '<div style="width:210px;float:left;margin-right:20px;margin-bottom:10px;">';
						$image_src = base_url().'images/studentschedule/'.$student_schedule['schedule_src'];
						echo '<img title="view image" class="img-popup" style="width:210px;cursor:pointer;max-width:210px;height:auto;border:2px solid #FFFFFF;box-shadow:0 0 3px rgba(0, 0, 0, 0.5);" src="'.$image_src.'" />';
						echo '<p style="text-align:center;margin-top:2px;">Year '.$year.' - Group '.$group.' - Semester '.$semester.'</p>';
					echo '</div>';
				}
			}
		}
		
		// Thesis page
		else if ( $external_resources == 'thesis' )
		{
			echo '<div class="page_title"><h1>Thesis</h1></div><br />';
			
			$all_thesis = $this->MThesis->getAllThesis();
			if ( count($all_thesis) > 0 )
			{
				foreach ( $all_thesis as $key => $thesis )
				{
					$thesis_topic = $thesis['topic'];
					$student_name1 = $thesis['stud1_lname'].' '.$thesis['stud1_fname'];
					$student_id1 = $thesis['stud1_id'];
					if ( $student_id1 > 0 ) $studentid1 = $student_id1;
					else $studentid1 = '&nbsp;';
					$student_group1 = $thesis['stud1_group'];
					$student_phone1 = $thesis['stud1_phone'];
					$student_name2 = $thesis['stud2_lname'].' '.$thesis['stud2_fname'];
					$student_id2 = $thesis['stud2_id'];
					if ( $student_id2 > 0 ) $studentid2 = $student_id2;
					else $studentid2 = '&nbsp;';
					$student_group2 = $thesis['stud2_group'];
					$student_phone2 = $thesis['stud2_phone'];
					$student_name3 = $thesis['stud3_lname'].' '.$thesis['stud3_fname'];
					$student_id3 = $thesis['stud3_id'];
					if ( $student_id3 > 0 ) $studentid3 = $student_id3;
					else $studentid3 = '&nbsp;';
					$student_group3 = $thesis['stud3_group'];
					$student_phone3 = $thesis['stud3_phone'];
					$student_name4 = $thesis['stud4_lname'].' '.$thesis['stud4_fname'];
					$student_id4 = $thesis['stud4_id'];
					if ( $student_id4 > 0 ) $studentid4 = $student_id4;
					else $studentid4 = '&nbsp;';
					$student_group4 = $thesis['stud4_group'];
					$student_phone4 = $thesis['stud4_phone'];
					$advisor = $thesis['lastname'].' '.$thesis['firstname'];
					
					echo "<table cellspacing='0' cellpadding='3' border='1' width='100%'>\n";
						echo '<tr style="background:#C98E11;">';
							echo '<td style="width:100px;border-top:1px black solid;border-bottom:1px black solid;"><strong>Topic</strong></td>';
							echo '<td colspan="4" style="border-top:1px black solid;border-bottom:1px black solid;"><strong>'.$thesis_topic.'</strong></td>';
						echo '</tr>';
						echo '<tr>';
							echo '<td rowspan="6"> Students </td>';
							echo '<tr>';
								echo '<td style="width:220px;border-bottom:1px black solid;border-top:1px black solid;font-weight:bold;">Student Name</td>';
								echo '<td style="border-bottom:1px black solid;border-top:1px black solid;font-weight:bold;">Student ID</td>';
								echo '<td style="border-bottom:1px black solid;border-top:1px black solid;font-weight:bold;">Group</td>';
								echo '<td style="border-bottom:1px black solid;border-top:1px black solid;font-weight:bold;">Telephone</td>';
							echo '</tr>';
							echo '<tr>';
								echo '<td>'.$student_name1.'</td>';
								echo '<td>'.$studentid1.'</td>';
								echo '<td>'.$student_group1.'</td>';
								echo '<td>'.$student_phone1.'</td>';
							echo '</tr>';
							echo '<tr>';
								echo '<td>'.$student_name2.'</td>';
								echo '<td>'.$studentid2.'</td>';
								echo '<td>'.$student_group2.'</td>';
								echo '<td>'.$student_phone2.'</td>';
							echo '</tr>';
							echo '<tr>';
								echo '<td>'.$student_name3.'</td>';
								echo '<td>'.$studentid3.'</td>';
								echo '<td>'.$student_group3.'</td>';
								echo '<td>'.$student_phone3.'</td>';
							echo '</tr>';
							echo '<tr>';
								echo '<td>'.$student_name4.'</td>';
								echo '<td>'.$studentid4.'</td>';
								echo '<td>'.$student_group4.'</td>';
								echo '<td>'.$student_phone4.'</td>';
							echo '</tr>';
						echo '</tr>';
						echo '<tr>';
							echo '<td style="border-top:1px black solid;"> Advisor </td>';
							echo '<td colspan="4" style="border-top:1px black solid;">'.$advisor.'</td>';
						echo '</tr>';
					echo '</table>';
				}
			}
		}
		
		else
		{
			echo '<div class="page_title"><h1>'.$page['name'].'</h1></div><br />';
			echo $page['content'];
		}
	}
?>